<?php
class LangController extends Zend_Controller_Action
{
	
    //don't need to render the layout, 'cause we don't need it, set lang to Zend_Registry and than redirect to previuos page 
    public function init ()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $init = new Model_Init($this);
    }
    public function enAction ()
    {
        $this->setLang('en');
    }
    public function ukAction ()
    {
        $this->setLang('uk');
    }
    public function ruAction ()
    {
        $this->setLang('ru');
    }
    //write lang value to session and collect to Zend_Regigstry translate, and that redirect to main page
    private function setLang ($language)
    {
        $localLangSession = new Zend_Session_Namespace('lang');
        $localLangSession->lang = $language;
        $localLang = $localLangSession->lang;
        $translate = new Zend_Translate('array', APPLICATION_PATH . '/languages', 
        $localLang, array('scan' => Zend_Translate::LOCALE_DIRECTORY));
        Zend_Registry::set('Zend_Translate', $translate);
        $this->_redirect();
    }
}

